<?php
/*
 *      ositemform.php
 *
 *      Copyright 2010 Vitaliy Rakitin <virak@ukr.net>
 *
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */

require_once($_SERVER['DOCUMENT_ROOT']."/classes/System/nwform.php");
require_once($_SERVER['DOCUMENT_ROOT']."/classes/GUI/nwmsg.php");

class ositemform extends nwform {

	private $object;
	//private $item;
	private $components = array();

	function __construct($object) {
		$this->uuid = $object->uuid;
		parent::__construct();
		$this->object = &$object;
		$this->caption = $this->object->name." - Редактирование";
		$this->body = $this->defaultbody();
	}

	function close() {
		parent::close();
	}

	function cancel() {
		parent::close();
	}

	function save() {
		$this->object->save();
		parent::close();
	}

/*
	function tables($uuid) {
		$this->item->tables->byuuid($uuid)->listform->show();
	}
*/
	

/*
	function onchange($fieldname, $value) {
		$this->object->$fieldname = $value;
	}
*/

	function defaultbody($readonly = false) {
		$out = "<table align='center'>";
		foreach($this->object->fields->getall() as $field) {
			$out .= "<tr>";
			$out .= "<th style='text-align:right;'>".$field->name."</th>";
			$out .= "<td style='border: solid black 1px;text-align:left;'>".$field->form."</td>";
			$out .= "</tr>";
		}
		$out .= "</table>";
/*
		foreach($this->object->tables->getall() as $table) {
			$out .= "<input type='button' name='close' value='".$table["name"]."' onclick=message('$this->uuid','tables','".$table["id"]."',0);>";
		}
*/
		$out .= "<br>";
		$out .= "<input type='button' name='close' value='Save' onclick=message('$this->uuid','save','',0);>";
		$out .= "<input type='button' name='close' value='Cancel' onclick=message('$this->uuid','cancel','',0);>";
		return $out;
	}
}
?>

